package com.dongdong.controller;

import com.dongdong.em.Result;
import com.dongdong.service.ContentCategoryService;
import com.dongdong.vo.ContentCategoryVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("contentCategory")
@RefreshScope               //开启热更新
public class ContentCategoryController {

    @Autowired
    private ContentCategoryService categoryService;

    @PostMapping("getCategoryList")
    public Result getCategoryList() {
        List<ContentCategoryVO> volist = categoryService.getCategoryList();
        return Result.OK().setData(volist);
    }

    @PostMapping("FindName")
    public Result FindName(@RequestBody ContentCategoryVO categoryVO) {
        List<ContentCategoryVO> voList = categoryService.FindName(categoryVO);
        return Result.OK().setData(voList);
    }

    @PostMapping("InsertCate")
    public Result InsertCate(@RequestBody ContentCategoryVO categoryVO) {
        int i = categoryService.InsertCate(categoryVO);
        if (i <= 0) {
            return Result.ERROR();
        }
        return Result.OK();
    }

    @DeleteMapping("DelCate")
    public Result DelCate(@RequestParam Long id) {
        int i = categoryService.DelCate(id);
        if (i <= 0) {
            return Result.ERROR();
        }
        return Result.OK();
    }

    @GetMapping("toUpte")
    public Result toUpte(@RequestParam Long id){
        ContentCategoryVO vo = categoryService.getById(id);
        return Result.OK().setData(vo);
    }

    @PutMapping("Update")
    public Result Update(@RequestBody ContentCategoryVO categoryVO){
        int i = categoryService.Update(categoryVO);
        if (i <=0 ){
            return Result.ERROR();
        }
        return Result.OK();
    }

    @DeleteMapping("deleteCate/{arr}")
    public Result deleteCate(@PathVariable Long[] arr){
        int i = categoryService.deleteCate(arr);
        if (i <= 0){
            return Result.ERROR();
        }
        return Result.OK();
    }
}
